package com.roadjava.convert.demo02;

import com.roadjava.beans.dto.CarDTO;
import com.roadjava.beans.dto.DriverDTO;
import com.roadjava.beans.vo.CarVO;
import com.roadjava.beans.vo.DriverVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public abstract class CarConvert02 {

    public static CarConvert02 INSTANCE = Mappers.getMapper(CarConvert02.class);

    @Mappings(
            value = {
                    @Mapping(source = "totalPrice", target = "totalPrice", numberFormat = "#.00"),
                    @Mapping(source = "publishDate", target = "publishDate", dateFormat = "yyyy-MM-dd HH:mm:ss"),
                    @Mapping(target = "price", ignore = true),
                    @Mapping(source = "brand", target = "brandName"),
                    @Mapping(source = "driverDTO", target = "driverVO")
            }
    )
    public abstract CarVO dto2vo(CarDTO carDTO);

    // 属性是引用对象的映射处理
    @Mapping(source = "id", target = "driverId")
    @Mapping(source = "name", target = "fullName")
    public abstract DriverVO driverDTO2DriverVO(DriverDTO driverDTO);

    // 集合批量映射
    public abstract List<CarVO> dtos2vos(List<CarDTO> carDTO);

}